$(function(){

books=JSON.parse(localStorage.getItem("books"));
layui.use(['laypage', 'layer'], function(){
    var laypage = layui.laypage
    ,layer = layui.layer;

    //调用分页
//     laypage.render({
//         elem: 'demo20'
//         ,count: books.length//数据总量
//         ,limit:books.length/2
//         ,jump: function(obj){
//             var imgs=document.getElementsByTagName("img");
//             var spans1=document.getElementsByClassName("price");
//             var spans2=document.getElementsByClassName("linethrouth");
//             var inputs=document.getElementsByClassName("layui-btn");
//             for(var i=0;i<books.length;i++){
//                 document.getElementById("word"+i+"").innerHTML=function(){
//                     var arr=[],
//                     thisBooks=books.concat().splice(obj.curr*obj.limit-obj.limit,obj.limit);
//                     arr.push("<p>"+thisBooks[i].desc+"</p>");
//                     return arr.join('');
//                 }();
//                 thisBooks=books.concat().splice(obj.curr*obj.limit-obj.limit,obj.limit);
//                 imgs[i].src="imgs/books/"+thisBooks[i].img;
//                 spans1[i].innerHTML="团购价"+thisBooks[i].newPrice;
//                 spans2[i].innerHTML=+thisBooks[i].oldPrice;
//                 inputs[i].value=(((thisBooks[i].newPrice)/(thisBooks[i].oldPrice))*10).toFixed(1)+"折";
//                 // document.getElementById("word"+i+"").innerHTML=thisBooks[i].desc;
//             }
//         }
//     });
       
        laypage.render({
            elem: 'demo20',
            limit:books.length/2
            ,count: books.length
            ,jump: function(obj){
            //模拟渲染
            document.getElementById('show').innerHTML = function(){
                var arr = []
                ,thisData = books.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
                    layui.each(thisData, function(index, item){
                        // console.log(item);//仓库中每本书的详细数据
                    arr.push(' <div class="showImgWord">'+
                                    '<img src="imgs/books/'+item.img+'" alt="">'+
                                    '<div class="word">'+
                                        '<div id="word0">'+
                                        '<p>'+item.desc+'</p>'+
                                        '</div>'+
                                        '<p class="buy"><span class="price">团购价'+item.newPrice+'</span><span class="linethrouth">'+item.oldPrice+'</span>'+
                                        '<input class="layui-btn layui-btn-sm layui-btn-normal " type="button" value="'+(((item.newPrice)/(item.oldPrice))*10).toFixed(1)+'折">'+
                                        '</p>'+
                                    '</div>'+
                                '</div>')
                    });
                    console.log(obj.curr);//1      2
                    console.log(obj.curr*obj.limit);//1*6   limit上面设置了为books.length/2           2*6
                    // console.log( obj.limit);//6
                    console.log(books.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit));//前6本书的详细数据          后6本书的详细数据
                return arr.join('');
               
            }();
            }
        });
});

});